﻿<UserControl x:Class="DaphneControls.PositionEditor"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:vm="clr-namespace:DaphneControls.ViewModel"            
             xmlns:loc="http://schemas.tomer.com/winfx/2006/xaml/presentation"             
             xmlns:cmd ="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WPF4"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"             
             mc:Ignorable="d" 
             d:DesignHeight="600" d:DesignWidth="500">
    <UserControl.DataContext>
        <vm:PositionEditorVM />
    </UserControl.DataContext>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition  Height="Auto"/>
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        
        <!-- Part of control displayed when not in setup mode -->
        <ContentControl Grid.Row="0">
            <StackPanel Orientation="Vertical">
                <TextBlock Text="{loc:Translate Default='The current checkersboard is not in setup mode.'}" 
                            Margin="10,10,0,0"/>
                <Button Content="{loc:Translate Default='Setup position'}" Width="150" Margin="10,15,0,0" 
                        Height="25" HorizontalAlignment="Left" Command="{Binding Path=StartEditCommand}" />
            </StackPanel>   
            
            <ContentControl.Style>
                <Style TargetType="ContentControl">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Path=InEditMode}" Value="True">
                            <Setter Property="Visibility" Value="Collapsed" />
                        </DataTrigger>                       
                    </Style.Triggers>                                      
                </Style>               
            </ContentControl.Style>
        </ContentControl>
        
        <!-- Part of XAML displayed when in edit mode -->
        <ContentControl Grid.Row="1">
            <StackPanel Orientation="Vertical">
                <!-- Undo/Redo buttons -->
                <GroupBox Header="{loc:Translate Default='Undo / Redo'}">
                    <StackPanel Orientation="Horizontal">
                        <Button Content="{loc:Translate Default=Undo}" Margin="10" Padding="3" Width="100" 
                                Command="{Binding Path=UndoCommand}" IsEnabled="{Binding Path=UndoButtonEnabled}" />
                        <Button Content="{loc:Translate Default=Redo}" Margin="10" Padding="3" Width="100"
                                Command="{Binding Path=RedoCommand}" IsEnabled="{Binding Path=RedoButtonEnabled}" />
                    </StackPanel>
                </GroupBox>

                <!-- Clear and Starting Position buttons -->
                <GroupBox Header="{loc:Translate Default='Starting positon / Clear board'}">
                    <StackPanel Orientation="Horizontal">
                        <Button Content="{loc:Translate Default='Set starting position'}" Margin="10" Padding="3" Width="150" 
                                Command="{Binding Path=SetStartingPositionCommand}" />
                        <Button Content="{loc:Translate Default='Clear board'}" Margin="10" Padding="3" Width="100" 
                                Command="{Binding Path=ClearBoardCommand}"/>
                    </StackPanel>
                </GroupBox>
                
                <!-- FEN -->
                <GroupBox Header="{loc:Translate Default='FEN Setup'}">
                    <StackPanel Orientation="Horizontal">
                        <TextBox Width="250" Margin="5" Text="{Binding Path=FEN, Mode=TwoWay}" />
                        <Button Width="80" Margin="5" Content="{loc:Translate Default='Set FEN'}"
                                Command="{Binding Path=ParseFENCommand}" />                        
                    </StackPanel>                                              
                </GroupBox>
                
                <!-- Side to move -->
                <GroupBox Header="{loc:Translate Default='Side to move'}">
                    <StackPanel Orientation="Horizontal">
                        <RadioButton Margin="8" GroupName="SideToMove" Content="{loc:Translate Default='White Player'}" 
                                     IsChecked="{Binding Path=WhitePlayerChecked, Mode=TwoWay}" >
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="Click">
                                    <cmd:EventToCommand Command="{Binding Path=SideToMoveCommand}" />                                    
                                </i:EventTrigger>                                
                            </i:Interaction.Triggers>                                                       
                        </RadioButton>
                        <RadioButton Margin="8" GroupName="SideToMove" Content="{loc:Translate Default='Black Player'}" 
                                     IsChecked="{Binding Path=BlackPlayerChecked, Mode=TwoWay}">
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="Click">
                                    <cmd:EventToCommand Command="{Binding Path=SideToMoveCommand}" />
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </RadioButton>
                    </StackPanel>
                </GroupBox>
                
                <!-- Final buttons -->
                <StackPanel Orientation="Horizontal" Margin="0,10,0,0">
                    <Button Margin="5" Padding="3" Width="150"  Content="{loc:Translate Default='Accept position'}"
                           Command="{Binding Path=ApproveCommand}" />
                    <Button Margin="5" Padding="3" Width="150"  Content="{loc:Translate Default='Cancel editing'}"
                            Command="{Binding Path=CancelCommand}" />
                </StackPanel>                             
            </StackPanel>

            <ContentControl.Style>
                <Style TargetType="ContentControl">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Path=InEditMode}" Value="False">
                            <Setter Property="Visibility" Value="Collapsed" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </ContentControl.Style>
        </ContentControl>           
    </Grid>
</UserControl>
